<template>
  <div class="home">
   
    <!-- <input type="text"> -->
     <input type="text" v-model="msg" >
        <p>{{msg}}</p>
  </div>
</template>

<script>
function throttle(fn,delay=500){
    let timer =null;
    return function(){
        if(timer){
            return
        }
        timer =setTimeout(()=>{
            fn.apply(this)
            timer =null
        },delay)
    }
    // fn必须一个functon
}
export default {
data(){
  return{
    msg:"你好的名字"
  }
},
watch:{
     msg:throttle(function(){
    this.getSearch(this.msg);
  })
},
methods:{
  getSearch(val){
      var url =`http://122.112.161.135:3000/search?keywords=${val}`
                console.log(url);
  }
}
}
</script>
